package com.e3.sysmg.security.dao;

import java.util.List;

import com.e3.core.base.SuperDAO;
import com.e3.sysmg.security.entity.ModuleEntity;
import com.e3.sysmg.security.entity.RoleEntity;
import com.e3.sysmg.security.model.RoleQC;

public class RoleDAO extends SuperDAO {
	
	private String querySQL = "SELECT role FROM RoleEntity role";

	public List<RoleEntity> getAllRoles(){
		return this.find(querySQL);
	}
	
	public List<RoleEntity> getRolesByCondition(RoleQC qc){
		String sql = querySQL;
		qc.setPrefix("role");
		String whereSQL = qc.getWhereSQL();
		if(whereSQL!=null&&whereSQL.length()>0){
			sql = sql + " WHERE " +whereSQL;
		}
		return this.find(sql);
	}
	
	public RoleEntity getRoleEntityByCode(String code){
		String whSql = " WHERE role.code=?";
		String sql = querySQL + whSql;
		List<RoleEntity> entities = this.find(sql, code);
		return (entities == null||entities.size()==0)?null:entities.get(0);
	}
}
